import React, { useEffect } from 'react'
import {useNavigate,useLocation} from "react-router-dom"
function UseToken({children}) {
    function NewCap(){
        const navigate=useNavigate()
        const {pathName}=useLocation()

        const token=localStorage.getItem("token")

        const whileList=['/login','/']

        useEffect(()=>{
            if(!token && !whileList.includes(pathName)){
                navigate("/login")
            }
        },[token,pathName])
        return children
    }
  return <NewCap></NewCap>
}

export default UseToken
